package com.ap.core.sqltype.util;

import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;

import java.sql.Timestamp;
import java.util.Date;

/**
 * Util class for sql type conversions
 */
public class SqlTypeUtil {

    /**
     * private constructor to avoid instantiation
     */
    private SqlTypeUtil(){
        //do-nothing
    }

    public static java.sql.Date getSqlDate(final LocalDate dateAsLocalDate){
        if(null != dateAsLocalDate){
            Date date = dateAsLocalDate.toDateMidnight().toDate();
            return new java.sql.Date(date.getTime());
        }
        return null;
    }

    public static java.sql.Timestamp getSqlTimeStamp(final LocalDateTime dateTimeAsLocalDateTime){
        if(null != dateTimeAsLocalDateTime){
            Timestamp timestamp = new Timestamp(dateTimeAsLocalDateTime.toDateTime().getMillis());
            return timestamp;
        }
        return null;
    }

    public static java.sql.Date getSqlDate(final Date dateAsDate){
        if(null != dateAsDate){
            return new java.sql.Date(dateAsDate.getTime());
        }
        return null;
    }
}
